package Sort;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/8/26-下午2:42
 * Since  :   1.0
 * Version:   1.0
 */
public class DividedSort {

    public  static  void divided(int [] arr,int left,int right,int[] temp){
        while (left<right){
            int mid=(left+right)/2;
            divided(arr,left,mid,temp);
            divided(arr,mid+1,right,temp);
            conquer(arr,left,mid,right,temp);



        }


    }

    private static void conquer(int[] arr, int left, int mid, int right, int[] temp) {
        int l=left;
        int r=mid+1;
        int index=0;
        while (l<=mid&&r<=right){
            if (arr[l]<=arr[r])
                temp[index++]=arr[l++];
            else
                temp[index++]=arr[r++];

        }

        while (l<=mid){
            temp[index++]=arr[l++];
        }
        while (r<=right){
            temp[index++]=arr[r++];
        }

        index=0;
        while (left<right){
            arr[index++]=temp[index++];
        }


    }
}
